package com.ssy.lingxi.order.model.vo.mobile.response;

import com.ssy.lingxi.order.model.vo.basic.response.OrderPayNodeDetailVO;
import com.ssy.lingxi.order.model.vo.basic.response.OrderProcessDetailVO;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 订单创建（下单）之前，查询供应会员的交易流程配置、会员支付策略等信息
 * @author 万宁
 * @version 2.0.0
 * @date 2021-09-26
 */
public class MobileProcessDetailVO implements Serializable {
    private static final long serialVersionUID = -2749083144219546291L;

    public MobileProcessDetailVO(OrderProcessDetailVO orderProcessDetail) {
        this.required = orderProcessDetail.getRequired();
        this.firstPayRate = orderProcessDetail.getFirstPayRate();
        this.payTypes = orderProcessDetail.getPayTypes().stream().flatMap(payType -> payType.getPayChannels().stream().map(payChannel -> new MobilePayTypeDetailVO(payType.getFundMode(), payType.getPayType(), payType.getPayTypeName(), payChannel.getPayChannel(), payChannel.getPayChannelName()))).sorted(Comparator.comparingInt(MobilePayTypeDetailVO::getPayType).thenComparingInt(MobilePayTypeDetailVO::getPayChannel)).collect(Collectors.toList());
        this.payNodes = orderProcessDetail.getPayNodes();
        this.hasContract = orderProcessDetail.getHasContract();
        this.contractId = orderProcessDetail.getContractId();
    }

    /**
     * 是否需要支付（当不需要支付时，前端不显示支付方式列表）
     */
    private Boolean required;

    /**
     * 如果需要支付，下单成功后的支付比例
     */
    private BigDecimal firstPayRate;

    /**
     * 支付方式列表
     */
    private List<MobilePayTypeDetailVO> payTypes;

    /**
     * 支付环节列表，如果需要支付，此列表不为空，否则为空
     */
    private List<OrderPayNodeDetailVO> payNodes;

    /**
     * 是否有电子合同，true-是，false-否
     */
    private Boolean hasContract;

    /**
     * 电子合同Id，当使用电子合同时，此Id不为0，否则为0
     */
    private Long contractId;

    public Boolean getRequired() {
        return required;
    }

    public void setRequired(Boolean required) {
        this.required = required;
    }

    public BigDecimal getFirstPayRate() {
        return firstPayRate;
    }

    public void setFirstPayRate(BigDecimal firstPayRate) {
        this.firstPayRate = firstPayRate;
    }

    public List<MobilePayTypeDetailVO> getPayTypes() {
        return payTypes;
    }

    public void setPayTypes(List<MobilePayTypeDetailVO> payTypes) {
        this.payTypes = payTypes;
    }

    public List<OrderPayNodeDetailVO> getPayNodes() {
        return payNodes;
    }

    public void setPayNodes(List<OrderPayNodeDetailVO> payNodes) {
        this.payNodes = payNodes;
    }

    public Boolean getHasContract() {
        return hasContract;
    }

    public void setHasContract(Boolean hasContract) {
        this.hasContract = hasContract;
    }

    public Long getContractId() {
        return contractId;
    }

    public void setContractId(Long contractId) {
        this.contractId = contractId;
    }
}
